package com.yan.test.test2;

/**
 * @author taoge
 * @Date 2024/8/9 19:57
 * @Description
 */
public class Print {
    private int index = 1;

    public synchronized void print(char c){
        if(index % 3 != 0){
            try {
                this.wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

        System.out.print(c);
        index++;
        this.notifyAll();
    }

    public synchronized void print(int i){
        if(index % 3 == 0){
            try {
                this.wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

        System.out.print(i);
        index++;
        this.notifyAll();
    }
}
